<?php

/**
 * LayoutBehavior class
 *
 * @author Julot <andy.julot@gmail.com>
 * @since Monday, January 30, 2012. 09:21 AM
 */
class LayoutBehavior extends CBehavior {

	public function getMenu() {
		static $menu = null;
		
		if (isset($menu)) {
			return $menu;
		}
		
		$menu = array(
			array(
				'label'=>'Home',
				'url'=>array('/site/index'),
			),
			array(
				'label'=>'Measurement',
				'url'=>array('/measurement/reportDetailPeriodic'),
				'visible'=>!Yii::app()->user->isGuest,
			),
			array(
				'label'=>'Device',
				'url'=>array('/device/index'),
				'visible'=>!Yii::app()->user->isGuest,
			),
			array(
				'label'=>'Channel',
				'url'=>array('/channel/index'),
				'visible'=>!Yii::app()->user->isGuest,
			),
			array(
				'label'=>'Login',
				'url'=>array('/site/login'),
				'visible'=>Yii::app()->user->isGuest,
			),
			array(
				'label'=>'Logout (' . Yii::app()->user->name . ')',
				'url'=>array('/site/logout'),
				'visible'=>!Yii::app()->user->isGuest,
			)
		);

		return $menu;
	}

	private $_assetsUrl;

	public function getAssetsUrl() {
		if ($this->_assetsUrl === null) {
			$path = Yii::getPathOfAlias("application.assets");
			$this->_assetsUrl = Yii::app()->assetManager->publish(
					$path, false, -1, YII_DEBUG
			);
		}
		return $this->_assetsUrl;
	}

}
